

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HelloWorld
 */
public class HelloWorld extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private int count = 0;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HelloWorld() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		Enumeration<String> headerNames = request.getHeaderNames();
		count++;

		out.println("<HTML>");
		out.println("<HEAD><TITLE>");
		out.println("Hello World");
		out.println("</TITLE></HEAD>");
		out.println("<BODY>");
		out.println("<H1>" + "Hello World" + "</H1>");
		out.println("<P>");
		out.println("Hello " + request.getParameter("userName") + " sie sind der " + count + " Benutzer dieser Seite" + "</br></br>");
		out.println("<form method=POST>");
		out.println("<input type=submit name=submit value=reset>");
		out.println("</form>");
		
		while(headerNames.hasMoreElements()) {
			String headerName = headerNames.nextElement();
			out.print(headerName + ": ");
			out.println(request.getHeader(headerName) + "</br>");
		}
		
		out.println("</BODY></HTML>");
		out.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		count = 0;
	}

}
